{% extends "scheduling/base.html" %}
{% load static %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2><i class="fas fa-tools me-2"></i>维修管理</h2>
        <a href="{% url 'add_maintenance' %}" class="btn btn-primary">
            <i class="fas fa-plus-circle me-2"></i>添加维修记录
        </a>
    </div>

    <div class="card">
        <div class="card-header">
            <h4 class="mb-0">车辆维修记录</h4>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead class="table-light">
                        <tr>
                            <th>车牌号</th>
                            <th>开始日期</th>
                            <th>结束日期</th>
                            <th>维修时长</th>
                            <th>维修原因</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for record in maintenance_records %}
                        <tr>
                            <td>{{ record.bus.bus_id }}</td>
                            <td>{{ record.start_date|date:"Y-m-d" }}</td>
                            <td>
                                {% if record.end_date %}
                                {{ record.end_date|date:"Y-m-d" }}
                                {% else %}
                                <span class="text-muted">维修中</span>
                                {% endif %}
                            </td>
                            <td>{{ record.duration }}天</td>
                            <td>{{ record.reason }}</td>
                            <td>
                                {% if record.end_date %}
                                <span class="badge bg-success">已完成</span>
                                {% else %}
                                <span class="badge bg-warning">维修中</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if not record.end_date %}
                                <a href="{% url 'end_maintenance' record.id %}" class="btn btn-sm btn-outline-success" onclick="return confirm('确定要结束该维修记录吗？')">
                                    <i class="fas fa-wrench"></i> 结束维修
                                </a>
                                {% endif %}
                                <a href="{% url 'delete_maintenance' record.id %}" class="btn btn-sm btn-outline-danger" onclick="return confirm('确定要删除该维修记录吗？')">
                                    <i class="fas fa-trash-alt"></i> 删除
                                </a>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="7" class="text-center py-4">暂无维修记录</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}